package controllers;

import models.ClubUser;
import models.User;

public class Profile extends ConnectedUser {

	public static void info() {
		render();
	}

	public static void profileEditInfo() {
		render();
	}

	public static void profileChangePwd() {
		render();
	}

	public static void changeInfo(String name, String email, String desc) {
		connectedUser.name = name;
		connectedUser.email = email;
		connectedUser.desc = desc;
		connectedUser.save();
		
		flash.success("Your information has been successfully changed!");
		info();
	}

	public static void changePwd(Long id, String password, String newPassword, String repeatNewPassword) {
		if (connectedUser == null || !connectedUser.checkPassword(password)) {
			flash.error("Bad password");
			profileChangePwd();
		} else {
			if (newPassword.equals(repeatNewPassword)) {
				connectedUser.password = newPassword;
				connectedUser.save();
				flash.success("Password has been successfully changed!");
				info();
			} else {
				flash.error("Please input again");
				profileChangePwd();
			}
		}
	}
}
